﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Text.Editor.DragDrop;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Shell;
using FunctionPoint.UIManagers;
using FCommon = FunctionPoint.Common;
using Microsoft.VisualStudio.Utilities;
using Microsoft.VisualStudio.Text.Editor;
using System.Diagnostics;
namespace FunctionPoint.Handlers
{
    [Export(typeof(IDropHandlerProvider))]
    [DropFormat(FCommon.Constants.DROPHANDLER_DROPFORMAT_TEXT)]
    [DropFormat(FCommon.Constants.DROPHANDLER_DROPFORMAT_CUSTOMDATAFORMAT)]
    [DropFormat(FCommon.Constants.DROPHANDLER_DROPFORMAT_VSPROJECTITEM)]
    [DropFormat(FCommon.Constants.DROPHANDLER_DROPFORMAT_FILEDROP)]
    
    [DropFormat(FCommon.Constants.DROPHANDLER_DROPFORMAT_MULTIURL)]
    [Name(FCommon.Constants.DROPHANDLER_VSCODEDRAG_HANDLERNAME)]
    [Order]
    public class CodeDragDropHandlerProvider : IDropHandlerProvider, IEditorOperationsFactoryService
    {

        [Import(typeof(IEditorOperationsFactoryService))]
        public IEditorOperationsFactoryService EditorOperationsFactoryService { get; set; }

        [Import(typeof(SVsServiceProvider))]
        private IServiceProvider VsServiceProvider { get; set; }

        public IDropHandler GetAssociatedDropHandler(IWpfTextView wpfTextView)
        {
            Debug.WriteLine("Entering Constructor of GetAssociatedDropHandler for CodeDragDropProvider");
            
            IEditorOperations editorOperations = EditorOperationsFactoryService.GetEditorOperations(wpfTextView) as IEditorOperations;

           

            return wpfTextView.Properties.GetOrCreateSingletonProperty<CodeDragDropHandler>(
                () => new CodeDragDropHandler(wpfTextView, editorOperations));
        }

        public IEditorOperations GetEditorOperations(ITextView textView)
        {
            IEditorOperationsFactoryService editorOperationsService =
               ServiceProvider.GlobalProvider.GetService(typeof(IEditorOperationsFactoryService)) as IEditorOperationsFactoryService;

            return editorOperationsService.GetEditorOperations(textView);
        }
    }
}
